
const app = {
    state: {
        // 中英文
        language: localStorage.getItem('language') || 'en_US',
        //token
        token: localStorage.getItem('token') || '',
        //用户信息
        userInfo: localStorage.getItem('userInfo') && JSON.parse(localStorage.getItem('userInfo')) || null,
        //搜索历史
        searchHistory: localStorage.getItem('searchHistory') && JSON.parse(localStorage.getItem('searchHistory')) || [],
        //原始分类数据list
        oriClassList: localStorage.getItem('oriClassList') && JSON.parse(localStorage.getItem('oriClassList')) || [],
        //分类list
        classList: localStorage.getItem('classList') && JSON.parse(localStorage.getItem('classList')) || [],
    },
    mutations: {
        // 中英文
        SET_LANGUAGE: (state, language) => {
            state.language = language
            localStorage.setItem('language', language)
        },
        // token
		SET_TOKEN: (state, token) => {
			state.token = token
			localStorage.setItem('token', token)
		},
        // 用户信息
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo
			localStorage.setItem('userInfo', JSON.stringify(userInfo))
		},
        //搜索历史
        SET_SEARCHHISTORY: (state, searchHistory) => {
			state.searchHistory = searchHistory
			localStorage.setItem('searchHistory', JSON.stringify(searchHistory))
		},
        //原始分类数据list
        SET_ORICLASSLIST: (state, oriClassList) => {
			state.oriClassList = oriClassList
			localStorage.setItem('oriClassList', JSON.stringify(oriClassList))
		},
        //分类list
        SET_CLASSLIST: (state, classList) => {
			state.classList = classList
			localStorage.setItem('classList', JSON.stringify(classList))
		},

    },
    actions: {
        // 中英文
        setLanguage({
            commit
        }, language) {
            commit('SET_LANGUAGE', language)
        },
        // token
		setToken({
			commit
		}, token) {
			commit('SET_TOKEN', token)
		},
        // userInfo
		setUserInfo({
			commit
		}, userInfo) {
			commit('SET_USERINFO', userInfo)
		},
        // searchHistory
		setSearchHistory({
			commit
		}, searchHistory) {
			commit('SET_SEARCHHISTORY', searchHistory)
		},
        //oriClassList
        setOriClassList({
			commit
		}, oriClassList) {
			commit('SET_ORICLASSLIST', oriClassList)
		},
        //classList
        setClassList({
			commit
		}, classList) {
			commit('SET_CLASSLIST', classList)
		},

    }

}

export default app